﻿
using GameFramework.Event;
using GameFramework.Fsm;
using GameFramework.Procedure;
using UnityEngine;
using UnityGameFramework.Runtime;
/// <summary>
/// Pvp对抗
/// </summary>
public class PvpAgainstProcedure : GameBaseProcedure
{
    protected override void OnEnter(IFsm<IProcedureManager> procedureOwner)
    {
        base.OnEnter(procedureOwner);
        
        EntityInst.UI.CloseAllLoadedUIForms();
        
        Log.Info("Pvp对抗");
        EntityInst.Event.Subscribe(LoadSceneSuccessEventArgs.EventId,OnSceneLoadSuccess);
        EntityInst.Event.Subscribe(LoadSceneFailureEventArgs.EventId, OnSceneLoadFailure);

       // UnityEngine.SceneManagement.SceneManager.LoadScene("PvpAginest");
       EntityInst.Scene.LoadScene(AssetUtility.GetScene("PvpAginest"),this);
    }
    

    protected override void OnLeave(IFsm<IProcedureManager> procedureOwner, bool isShutdown)
    {
        base.OnLeave(procedureOwner, isShutdown);
    }

    private void OnSceneLoadSuccess(object sender, GameEventArgs arg)
    {
        var ne = arg as LoadSceneSuccessEventArgs;
        if (ne.UserData != this)
            return;
        
        Debug.Log($"load scene {ne.SceneAssetName} success");
    }

    private void OnSceneLoadFailure(object sender, GameEventArgs arg)
    {
        var ne = arg as LoadSceneFailureEventArgs;
        if (ne.UserData != this)
            return;

        Debug.LogError($"load scene error, message = {ne.ErrorMessage}");
    }
}
